<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>
<%@ taglib prefix="fn"  uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ page import="kr.co.insoft.framework.config.Authorities" %>
<c:set var="CONTEXT">${pageContext.request.contextPath}</c:set>
<c:set var="cssUrl">${pageContext.request.contextPath}/resources/css</c:set>
<c:set var="imgUrl">${pageContext.request.contextPath}/resources/images</c:set>
<c:set var="jsUrl">${pageContext.request.contextPath}/resources/js</c:set>
<form:form modelAttribute="compositeEntityModel" role="form" action="" method="post" class="form-horizontal">
	<form:input type="hidden" path="serviceid"/>
	<div class="form-group">
		<label for="projectName" class="col-sm-2 control-label">상위 프로젝트</label>
		<div class="col-sm-10">${compositeEntityModel.service.project.projectName }</div>
	</div>
	<div class="form-group">
		<label for="projectName" class="col-sm-2 control-label">상위 서비스</label>
		<div class="col-sm-10">${compositeEntityModel.service.serviceName }</div>
	</div>
	<div class="form-group">
		<label for="compositeName" class="col-sm-2 control-label">VM Composite Name</label>
		<div class="col-sm-10">${compositeEntityModel.compositeName }</div>
	</div>
	<div class="form-group">
		<label for="compositeName" class="col-sm-2 control-label">HA Configurations</label>
		<c:forEach items="${hatypes }" var="hatype">
			<c:if test="${hatype.getVal() eq  compositeEntityModel.compositeHatype}">${hatype.getDesc() }</c:if>
		</c:forEach>
	</div>
	<div class="form-group">
		<label for="compositeDesc" class="col-sm-2 control-label">VM Composite Desc</label>
		<div class="col-sm-10"><pre>${compositeEntityModel.compositeDesc }</pre></div>
	</div>
	<div class="form-group">
		<label for="inputPassword3" class="col-sm-2 control-label">환경변수</label>
		<div class="col-sm-10">
			<div class="col-sm-12 text-right"></div>
			<div class="col-sm-12 panel-group" id="variablesArea">
			<c:forEach items="${compositeEntityModel.variables }" var="sEVEntityModel">
			<div class="form-horizontal variablePanel" id="variable${sEVEntityModel.variableid }">
				<input type="hidden" id="variable" name="variable" value="${sEVEntityModel.variableid }"/>
				<div class="panel panel-default">
			    	<div class="panel-heading">
			    		<h4 class="panel-title">
			    			<a data-toggle="collapse" data-parent="#variablesArea" href="#collapse${sEVEntityModel.variableid }">${sEVEntityModel.variableName }</a>
			    		</h4>
			   		</div>
				</div>
				<div id="collapse${sEVEntityModel.variableid }" class="panel-collapse collapse variablePanel">
					<div class="form-group">
						<label for="variableDesc" class="col-sm-2 control-label"><spring:message code="common.description"/></label>
						<div class="col-sm-10"><textarea readonly="readonly" disabled="disabled" class="form-control">${sEVEntityModel.variableDesc }</textarea></div>
					</div>
					<div class="form-group">
						<label for="variables" class="col-sm-2 control-label"><spring:message code="configration.sev.variables"/></label>
						<div class="rows text-right col-sm-10">
							<table class="table table-hover targetVariableMapTable topmargin20">
								<thead>
									<tr>
										<th class="col-sm-2"><spring:message code="configration.sev.type"/></th>
										<th class="col-sm-8"><spring:message code="configration.sev.attribute"/></th>
										<th class="col-sm-1"></th>
									</tr>
								</thead>
								<tbody>
									<c:forEach items="${sEVEntityModel.variables }" var="variable" varStatus="status">
									<tr>
										<td class="col-sm-2 selectRows">
											<select class="form-control variableTypesSelect" name="tp" id="tp" readonly="readonly" disabled="disabled">
												<option value=""><spring:message code="select.seleted.message"/></option>
												<c:choose>
													<c:when test="${variable.array}">
														<option value="String">String</option>
														<option value="Integer">Integer</option>
														<option value="Double">Double</option>
														<option value="Option">Option</option>
														<option value="Array" selected="selected">Array</option>
													</c:when>
													<c:otherwise>
														<c:choose>
															<c:when test="${variable.tp eq 'String'}">
																<option value="String" selected="selected">String</option>
																<option value="Integer">Integer</option>
																<option value="Double">Double</option>
																<option value="Option">Option</option>
																<option value="Array">Array</option>
															</c:when>
															<c:when test="${variable.tp eq 'Integer'}">
																<option value="String">String</option>
																<option value="Integer" selected="selected">Integer</option>
																<option value="Double">Double</option>
																<option value="Option">Option</option>
																<option value="Array">Array</option>
															</c:when>
															<c:when test="${variable.tp eq 'Double'}">
																<option value="String">String</option>
																<option value="Integer">Integer</option>
																<option value="Double" selected="selected">Double</option>
																<option value="Option">Option</option>
																<option value="Array">Array</option>
															</c:when>
															<c:when test="${variable.tp eq 'Option'}">
																<option value="String">String</option>
																<option value="Integer">Integer</option>
																<option value="Double">Double</option>
																<option value="Option" selected="selected">Option</option>
																<option value="Array">Array</option>
															</c:when>
														</c:choose>
													</c:otherwise>
												</c:choose>
											</select>
										</td>
										<c:choose>
											<c:when test="${!variable.array and (variable.tp eq 'String') or (variable.tp eq 'Integer') or (variable.tp eq 'Double')  }">
												<td class="col-sm-8">
													<input type="text" class="form-control" id="title" name="title" readonly="readonly" disabled="disabled" value="${variable.title }"/>
													<div class="variableTypes variableTypeSingleValue panel panel-default variablePanel">
														<div class='panel-body'>
															<input type='text' class='form-control' name='val' id='val' readonly="readonly" disabled="disabled" value="${variable.val }"/>
														</div>
													</div>
												</td>
											</c:when>
											<c:when test="${!variable.array and variable.tp eq 'Option' }">
												<td class="col-sm-8">
													<input type="text" class="form-control" name="title" id="title" readonly="readonly" disabled="disabled" value="${variable.title }"/>
													<div class="variableTypes variableTypeOption panel panel-default variablePanel">
														<c:forTokens items="${variable.opt }" delims=";"  var="opt">
														<div class='panel-body optionRows'>
															<div class="input-group">
																<span class="input-group-addon"><input type="radio" readonly="readonly" disabled="disabled" class="variableOptions" name="vals" id="vals" value="${opt }" <c:if test="${opt eq variable.val }">checked="checked"</c:if> name="variables[${status.index }].vals"></span>
														      	<input type="text" readonly="readonly" disabled="disabled" class="form-control variableOptions" name="opts" id="opts" value="${opt }">
														      	<input type='hidden' class='form-control' name='rows' id='rows' placeholder='System Variable Value'  value="${variable.cols }"/>
																<input type='hidden' class='form-control' name='cols' id='cols' placeholder='System Variable Value' value="${variable.rows }"/>
														    </div>
														</div>
														</c:forTokens>
													</div>
												</td>
											</c:when>
											<c:when test="${variable.array }">
												<td class="col-sm-8">
													<div class='col-sm-12'>
														<div class='col-sm-5'><input type='text' name='title' id='title' class='form-control' readonly="readonly" disabled="disabled" value="${variable.title }"/></div>
														<div class='col-sm-4'></div>
														<div class='col-sm-3'></div>
													</div>
													<table class='table table-striped topmargin50 cdtArrayTable'>
														<thead><tr>
														<c:forEach items="${variable.arrays }" var="variableArray" varStatus="varrayStatus">
															<c:if test="${varrayStatus.first}">
																<c:forEach items="${variableArray }" var="tds">
																	<th>${tds.header }</th>
																</c:forEach>
																<th></th>
															</c:if>
														</c:forEach>
														</tr></thead>
														<tbody>
														<c:forEach items="${variable.arrays }" var="variableArray" varStatus="varrayStatus">
															<tr>
																<c:forEach items="${variableArray }" var="tds">
																	<td>
																	<c:choose>
																		<c:when test="${(tds.tp eq 'String') or (tds.tp eq 'Integer') or (tds.tp eq 'Double') }">
																			<input type="text" id='val' name='val' value="${tds.val }" class="form-control" readonly="readonly" disabled="disabled"/>
																			<input type='hidden' id='header' name='header' value='${tds.header }'/>
																			<input type='hidden' id='tp' name='tp' value='${tds.tp }'/>
																		</c:when>
																		<c:otherwise><!-- Option -->
																			<input type="text" class="form-control" id='val' name='val' value="${tds.val }" readonly="readonly" disabled="disabled"/>
																			<input type='hidden' id='header' name='header' value='${tds.header }'/>
																			<input type='hidden' id='tp' name='tp' value='${tds.tp }'/>
																		</c:otherwise>
																	</c:choose>
																	</td>
																</c:forEach>
																<td></td>
															</tr>
														</c:forEach>
														</tbody>
													</table>
												</td>
											</c:when>
										</c:choose>
										<td class="col-sm-1"></td>
										</tr>
									</c:forEach>
								</tbody>
							</table>
						</div>
					</div>
				</div>
			</div>
			</c:forEach>
			</div>
		</div>
	</div>
</form:form>